package com.zhaoyd.uaademo.service;

import com.zhaoyd.uaademo.core.orm.BaseMapper;
import com.zhaoyd.uaademo.core.orm.BaseService;
import com.zhaoyd.uaademo.entity.SysRole;
import com.zhaoyd.uaademo.mapper.SysRoleMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author zhaoyd
 * @date 2020-10-31 19:04
 */
@Service
public class SysRoleService extends BaseService<SysRole> {
    @Resource
    private SysRoleMapper sysRoleMapper;
    @Override
    protected BaseMapper<SysRole> dao() {
        return sysRoleMapper;
    }

    public List<SysRole> listRoleByUser(Integer userId){
        return sysRoleMapper.listRoleByUser(userId);
    }

    public Set<String> listRoleCodeByUser(Integer userId){
        List<SysRole> sysRoles = this.listRoleByUser(userId);
        Set<String> roleCodes = new HashSet<>();
        sysRoles.forEach(sysRole -> {
            roleCodes.add(sysRole.getCode());
        });
        return roleCodes;
    }
}
